package com.zmn.oms.admin.controller.work.modify;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.google.common.collect.Lists;
import com.zmn.base.channel.common.dro.ChannelDRO;
import com.zmn.base.common.data.common.constant.TagConsts;
import com.zmn.base.common.data.common.dro.marketing.shop.MarketingShopDRO;
import com.zmn.base.common.data.common.dro.tags.TagsDRO;
import com.zmn.base.product.common.consts.BaseProductConsts;
import com.zmn.base.product.common.dto.categ.CategServDRO;
import com.zmn.base.product.common.dto.product.ProductBaseQuery;
import com.zmn.base.product.common.dto.product.ec.ProductBaseDRO;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dictionary.GlobalDict;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.oms.admin.controller.work.WorkBaseController;
import com.zmn.oms.business.interfaces.base.BaseCodeService;
import com.zmn.oms.business.interfaces.order.DuplicateOrderBService;
import com.zmn.oms.common.constant.*;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.common.enums.ServiceItemTypeEnum;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.common.utils.ExceptionUtil;
import com.zmn.oms.common.utils.MobileUtil;
import com.zmn.oms.common.vo.KVDict;
import com.zmn.oms.model.bo.order.OrderBO;
import com.zmn.oms.model.dto.common.ChannelListQuery;
import com.zmn.oms.model.dto.order.zmn.FactoryUpdateOrderDTO;
import com.zmn.oms.model.dto.order.zmn.ZsNormalUpdateOrderDTO;
import com.zmn.oms.model.dto.product.OrderProductDTO;
import com.zmn.oms.model.dto.product.ProductQueryDTO;
import com.zmn.oms.model.dto.work.modify.SuspectedDuplicateOrderDTO;
import com.zmn.oms.model.dto.work.modify.VerifyTelephoneOrProductDTO;
import com.zmn.oms.model.dto.work.schedule.WorkOrderScheduleQuery;
import com.zmn.oms.model.entity.advancequote.AdvanceQuoteBaseQuery;
import com.zmn.oms.model.entity.advancequote.AdvanceQuoteItemQuery;
import com.zmn.oms.model.entity.advancequote.AdvanceQuoteOpenQuery;
import com.zmn.oms.model.entity.advancequote.AdvanceQuotePhenQuery;
import com.zmn.oms.model.entity.detail.OrderDetail;
import com.zmn.oms.model.entity.orderfinalpricequotation.OrderFinalPriceQuotation;
import com.zmn.oms.model.entity.orderfinalpricequotation.OrderFinalPriceQuotationQuery;
import com.zmn.oms.model.entity.product.OrderProduct;
import com.zmn.oms.model.entity.remark.OrderRemark;
import com.zmn.oms.model.entity.remark.OrderRemarkDetail;
import com.zmn.oms.model.entity.serviceitem.OrderServiceItem;
import com.zmn.oms.model.entity.shop.OrderExternalShop;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.model.vo.order.advanceQuote.CategVO;
import com.zmn.oms.model.vo.order.advanceQuote.ProductVO;
import com.zmn.oms.model.vo.shop.ExternalShopVO;
import com.zmn.oms.model.vo.work.OperatePermissionVO;
import com.zmn.oms.model.vo.work.ZsNormalUpdateOrderVO;
import com.zmn.oms.model.vo.work.compensate.CompensateVO;
import com.zmn.oms.model.vo.work.refund.RefundVO;
import com.zmn.oms.services.interfaces.orderfinalpricequotation.OrderFinalPriceQuotationService;
import com.zmn.oms.services.interfaces.remark.OrderRemarkDetailService;
import com.zmn.oms.services.interfaces.remark.OrderRemarkService;
import com.zmn.oms.services.interfaces.serviceitem.OrderServiceItemService;
import com.zmn.oms.services.interfaces.shop.OrderExternalShopService;
import com.zmn.oms.zmn.business.interfaces.compensate.CompensateBService;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkBService;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkOperatePermissionBService;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkScheduleBService;
import com.zmn.oms.zmn.normal.business.interfaces.order.FactoryOrderBService;
import com.zmn.oms.zmn.normal.business.interfaces.order.advancequote.AdvanceQuoteListBService;
import com.zmn.oms.zmn.normal.business.interfaces.refund.RefundBService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 类描述：订单修改/复制
 *
 * @author liuying
 * @date 2018/12/10 17:45
 */
@Slf4j
@Controller
@RequestMapping("/work/modify")
public class WorkModifyController extends WorkBaseController {

    @Autowired
    private ZsOrderWorkBService zsOrderWorkBService;
    @Autowired
    private ZsOrderWorkScheduleBService zsOrderWorkScheduleBService;
    @Resource
    private BaseCodeService baseCodeService;
    @Autowired
    private ZsOrderWorkOperatePermissionBService orderWorkOperatePermissionBService;
    @Autowired
    private FactoryOrderBService factoryOrderBService;
    @Autowired
    private RefundBService refundBService;
    @Autowired
    private CompensateBService compensateBService;
    @Autowired
    private DuplicateOrderBService duplicateOrderBService;
    @Autowired
    private OrderRemarkDetailService orderRemarkDetailService;
    @Autowired
    private OrderRemarkService orderRemarkService;
    @Autowired
    private OrderExternalShopService orderExternalShopService;
    @Resource
    private OrderFinalPriceQuotationService orderFinalPriceQuotationService;
    @Resource
    private AdvanceQuoteListBService advanceQuoteListBService;
    @Autowired
    private OrderServiceItemService orderServiceItemService;

    @NacosValue(value = "${advance.special.faultphenId:0}", autoRefreshed = true)
    private Integer specialFaultPhenId;

    /**
     * 复制
     */
    @RequestMapping(value = "copy")
    public ModelAndView copy(Long orderId, Long workId) {

        ModelAndView mv = new ModelAndView("work/modify/copy");

        // 查询订单
        OrderBO orderBO = orderWorkBService.findOrderWork(orderId, workId);
        OrderWork orderWork = orderBO.getOrderWork();

        ZsNormalUpdateOrderVO zsNormalUpdateOrderVO = this.setNormalOrderView(mv, orderBO, true, false);

        this.processCopyOrder(mv, orderWork, zsNormalUpdateOrderVO);

        return mv;
    }

    /**
     * 返修
     */
    @RequestMapping(value = "rework")
    public ModelAndView rework(Long orderId, Long workId) {
        ModelAndView mv = new ModelAndView("work/modify/rework");

        mv.addObject("isRework", true);

        // 查询订单
        OrderBO orderBO = orderWorkBService.findOrderWork(orderId, workId);
        OrderWork orderWork = orderBO.getOrderWork();
        OrderDetail orderDetail = orderBO.getOrderDetail();
        List<OrderProduct> orderProductList = orderBO.getOrderProductList();
        ZsNormalUpdateOrderVO zsNormalUpdateOrderVO = this.setNormalOrderView(mv, orderBO, true, true);

        // 设置返修
        zsNormalUpdateOrderVO.setReworkId(orderId);
        zsNormalUpdateOrderVO.setType(OrderConsts.ORDER_TYPE_REWORK);

        // 厂商单
        if (Objects.equals(OrderConsts.ORDER_SOURCE_TYPE_FACTORY, orderWork.getSourceType())) {
            mv.setViewName("factory/work/modify/rework");
        }
        // 非厂商单
        else {
//            zsNormalUpdateOrderVO.setChannelId(ChannelConsts.getReworkChannelId(zsNormalUpdateOrderVO.getPlatWork()));
//            zsNormalUpdateOrderVO.setSourceChannelId(NumberUtil.isNotNullOrZero(zsNormalUpdateOrderVO.getSourceChannelId()) ? zsNormalUpdateOrderVO.getSourceChannelId() : zsNormalUpdateOrderVO.getChannelId());
            // 返修单 使用原单渠道
            zsNormalUpdateOrderVO.setChannelId(zsNormalUpdateOrderVO.getChannelId());
            zsNormalUpdateOrderVO.setSourceChannelId(zsNormalUpdateOrderVO.getSourceChannelId());
            zsNormalUpdateOrderVO.setPlat(zsNormalUpdateOrderVO.getPlatWork());
        }

        // 处理联系人电话
        zsNormalUpdateOrderVO.setTelephone(orderDetail.getTelephone());

        // 返修单修改限制
        mv.addObject("disabledEdit", true);
        // 返修原因集合
        mv.addObject("reworkReasonList", this.listReworkReason());

        // 处理禁用产品
        Object servProductListObj = mv.getModel().get("servProductList");
        if (Objects.nonNull(servProductListObj)) {
            List<KVDict> servProductList = (List<KVDict>) servProductListObj;
            boolean findProduct = servProductList.stream().anyMatch(item -> Objects.equals(orderWork.getProductId(), item.getValue()));
            if (!findProduct) {
                OrderProduct orderProduct = orderProductList.stream().filter(item -> Objects.equals(orderWork.getProductId(), item.getProductId()))
                        .findAny().orElse(null);
                if (orderProduct != null) {
                    servProductList.add(KVDict.builder()
                            .value(orderProduct.getProductId())
                            .text(orderProduct.getProductName())
                            .disabled(false)
                            .pid(orderWork.getServCategId())
                            .ext1(orderProduct.getProductUnit())
                            .build());
                }
            }
        }

        return mv;
    }

    /**
     * 修改订单
     */
    @RequestMapping(value = "update")
    public ModelAndView update(Long orderId, Long workId, Integer moduleId) throws OmsBaseException {
        ModelAndView mv = new ModelAndView();

        // 查询订单
        OrderBO orderBO = orderWorkBService.findOrderWork(orderId, workId);

        mv.addObject("opType", OrderConsts.ORDER_OP_TYPE_INPUT);

        // 如果退款单-》跳转到退款单页面
        OrderWork orderWork = orderBO.getOrderWork();
        if (Objects.equals(orderWork.getType(), OrderConsts.ORDER_TYPE_REFUND)) {
            return this.jumpToRefundPage(orderId, workId, moduleId, mv);
        } else if (Objects.equals(orderWork.getType(), OrderConsts.ORDER_TYPE_COMPENSATE)) {
            return this.jumpToCompensatePage(orderId, workId, mv);
        }

        // 返修单显示禁用产品
        Integer orderType = orderBO.getOrderWork().getType();
        boolean includeDisabledProduct = Objects.equals(orderType, OrderConsts.ORDER_TYPE_REWORK);

        // 修改权限
        Set<String> updateDisabledFields = super.getUpdateDisabledFields(orderBO, moduleId);
        ZsNormalUpdateOrderVO zsNormalUpdateOrderVO = this.setNormalOrderView(mv, orderBO, false, includeDisabledProduct);

        // 设置订单修改view
        this.setUpdateView(mv, orderBO, updateDisabledFields);

        // 渠道列表
        this.setUpdateOrderChannelList(mv, zsNormalUpdateOrderVO, orderBO.getOrderWork().getBizModeSource());

        mv.addObject("moduleId", moduleId);
        Integer status = orderBO.getOrderWork().getStatus();
        boolean isVerify = Objects.equals(status, OrderStatusConsts.WORK_STATUS_DISTRIBUTE)
                || Objects.equals(status, OrderStatusConsts.WORK_STATUS_TAKE)
                || Objects.equals(status, OrderStatusConsts.WORK_STATUS_VISIT);
        mv.addObject("verifyChangeAddressOrDutyTimeOrProduct", isVerify);
        return mv;
    }


    private ModelAndView jumpToRefundPage(Long orderId, Long workId, Integer moduleId, ModelAndView mv) throws OmsBaseException {
        RefundVO refundVO = refundBService.getRefundVO(orderId, workId, true);
        mv.addObject("refundVO", refundVO);
        mv.addObject("orderId", orderId);
        mv.addObject("workId", workId);
        mv.addObject("maxRefundAmount", refundVO.getOriginalAmount() - refundVO.getHaveRefundAmount());
        mv.addObject("moduleId", moduleId);
        if (refundVO.isSupportBacktracking()) {
            mv.addObject("maxBacktrackingAmount", refundVO.getBacktrackingAmount() - refundVO.getHaveBacktrackingAmount());
        } else {
            mv.addObject("maxBacktrackingAmount", 0);
        }
        // 是否
        mv.addObject("yesOrNo", OrderConsts.getYesOrNoObj());
        // 修改标识
        mv.addObject("isUpdate", true);
        mv.setViewName("work/modify/refund");
        return mv;
    }

    private ModelAndView jumpToCompensatePage(Long orderId, Long workId, ModelAndView mv){
        mv.addObject("orderId", orderId);
        mv.addObject("workId", workId);
        mv.addObject("isUpdate", true);
        CompensateVO compensateVO = compensateBService.getCompensateVO(orderId, workId);
        mv.addObject("compensateVO", compensateVO);
        mv.setViewName("work/modify/compensate");
        return mv;
    }


    /**
     * 确认订单
     */
    @RequestMapping(value = "confirm")
    public ModelAndView confirm(Long orderId, Long workId, Integer moduleId) throws OmsBaseException {
        ModelAndView mv = new ModelAndView();

        // 查询订单
        OrderBO orderBO = orderWorkBService.findOrderWork(orderId, workId);

        mv.addObject("opType", OrderConsts.ORDER_OP_TYPE_CONFIRM);

        // 如果退款单-》跳转到退款单页面
        OrderWork orderWork = orderBO.getOrderWork();
        if (Objects.equals(orderWork.getType(), OrderConsts.ORDER_TYPE_REFUND)) {
            return this.jumpToRefundPage(orderId, workId, moduleId, mv);
        }

        Set<String> noUpdateRightField = super.getUpdateDisabledFields(orderBO, moduleId);

        // 确认，不确认时间不能勾选
        //noUpdateRightField.add("dutyFail");

        // 返修单显示禁用产品
        Integer orderType = orderBO.getOrderWork().getType();
        boolean includeDisabledProduct = Objects.equals(orderType, OrderConsts.ORDER_TYPE_REWORK);

        // 没有修改权限的字段
        ZsNormalUpdateOrderVO zsNormalUpdateOrderVO = this.setNormalOrderView(mv, orderBO, false, includeDisabledProduct);

        // 设置订单修改view
        this.setUpdateView(mv, orderBO, noUpdateRightField);

        // 渠道列表
        this.setUpdateOrderChannelList(mv, zsNormalUpdateOrderVO, orderBO.getOrderWork().getBizModeSource());

        return mv;
    }

    /**
     * 普通单修改
     */
    @PostMapping(value = "normal/save")
    @ResponseBody
    @SuppressWarnings("all")
    public ResultDTO saveUpdate(@RequestBody @Valid ZsNormalUpdateOrderDTO zsNormalUpdateOrderDTO,
                                @Param("opType") Integer opType) {
        try {

            // 验证预约时间范围
            zsOrderWorkScheduleBService.validateDutyTime(zsNormalUpdateOrderDTO.getOrderId(), zsNormalUpdateOrderDTO.getPlat(), ConfOrderDutyConsts.TYPE_OPERATION_PLATFORM, zsNormalUpdateOrderDTO.getDutyTime());

            Long orderId = zsNormalUpdateOrderDTO.getOrderId();
            Long workId = zsNormalUpdateOrderDTO.getWorkId();
            // 确认调整
            if (Objects.equals(opType, OrderConsts.ORDER_OP_TYPE_CONFIRM)) {
                Integer channelId = zsNormalUpdateOrderDTO.getChannelId();
                ResponseDTO<ChannelDRO> channelDRO = channelListRemoteService.getByChannelId(channelId);
                boolean rankBoolean = channelDRO.getData() != null && channelDRO.getData().getRank() != GlobalConsts.LEVEL_2;
                if (rankBoolean) {
                    return ResultDTO.fail("请联系技术人员确认渠道信息");
                }
                OperatePermissionVO operatePermission = orderWorkOperatePermissionBService.getOperatePermission(
                        orderId, workId, OrderConsts.ORDER_OP_TYPE_CONFIRM);
                if (!operatePermission.getCanOperate()) {
                    return ResultDTO.fail(operatePermission.getMsg());
                }

                zsNormalOrderBService.saveConfirmOrder(zsNormalUpdateOrderDTO);
            }
            // 修改
            else {
                OperatePermissionVO operatePermission = orderWorkOperatePermissionBService.getOperatePermission(
                        orderId, workId, OrderConsts.ORDER_OP_TYPE_UPDATE);
                if (!operatePermission.getCanOperate()) {
                    return ResultDTO.fail(operatePermission.getMsg());
                }

                // 子公司角色修改订单不触发分单撤回、派单撤回
                boolean branchCompany = super.isBranchCompany();
                zsNormalUpdateOrderDTO.setBranchCompany(branchCompany);
                if (branchCompany) {
                    zsNormalUpdateOrderDTO.setVerifyDistributeBack(!branchCompany);
                } else {
                    // 当前端不撤回时
                    if (!zsNormalUpdateOrderDTO.isVerifyDistributeBack()) {
                        zsNormalUpdateOrderDTO.setVerifyDistributeBack(zsNormalUpdateOrderDTO.isVerifyDistributeBack());
                    }
                }
                zsNormalUpdateOrderDTO.setVerifyAssignBack(!branchCompany);

                boolean verifyTelephoneOrProduct = verifyTelephoneOrProduct(zsNormalUpdateOrderDTO);

                zsNormalOrderBService.updateOrder(zsNormalUpdateOrderDTO);

                if (verifyTelephoneOrProduct) {
                    SuspectedDuplicateOrderDTO suspectedDuplicateOrderDTO = new SuspectedDuplicateOrderDTO();
                    BeanMapper.copy(zsNormalUpdateOrderDTO, suspectedDuplicateOrderDTO);
                    if (CollectionUtil.isNullOrEmpty(zsNormalUpdateOrderDTO.getOrderProductList())) {
                        return ResultDTO.success();
                    }
                    OrderProductDTO orderProductDTO = zsNormalUpdateOrderDTO.getOrderProductList().get(0);
                    suspectedDuplicateOrderDTO.setProductShowType(orderProductDTO.getProductShowType());
                    if (Objects.equals(orderProductDTO.getProductShowType(), 1)) {
                        suspectedDuplicateOrderDTO.setProductId(orderProductDTO.getProductId());
                    } else {
                        suspectedDuplicateOrderDTO.setProductId(orderProductDTO.getShowProductId());
                    }
                    // 送到 疑似重复跟单处理 消息队列
                    duplicateOrderBService.noticeSuspectedDuplicateOrderToMq(suspectedDuplicateOrderDTO);
                }
            }
            return ResultDTO.success();
        } catch (OmsBaseException e) {
            return ResultDTO.fail(e.getMessage());
        } catch (Exception e) {
            logger.error("{}", e.getMessage());
            logger.error(ExceptionUtil.getStackTrace(e));
            return ResultDTO.fail(e.getMessage());
        }
    }

    /**
     *  校验取消重复
     * @return
     */
    @RequestMapping("checkCancelDuplicateOrder")
    public ResultDTO checkCancelDuplicateOrder() {
        return ResultDTO.success();
    }


    /**
     * 厂商单修改
     */
    @PostMapping(value = "factory/save")
    @ResponseBody
    @SuppressWarnings("all")
    public ResultDTO saveFactoryUpdate(@RequestBody @Valid FactoryUpdateOrderDTO factoryUpdateOrderDTO,
                                       @Param("opType") Integer opType) {
        try {

            // 验证预约时间范围
            zsOrderWorkScheduleBService.validateDutyTime(factoryUpdateOrderDTO.getOrderId(), factoryUpdateOrderDTO.getPlat(), ConfOrderDutyConsts.TYPE_OPERATION_PLATFORM, factoryUpdateOrderDTO.getDutyTime());

            Long orderId = factoryUpdateOrderDTO.getOrderId();
            Long workId = factoryUpdateOrderDTO.getWorkId();
            OrderWork dbOrderWork = orderWorkService.findOrderWorkByKey(orderId, workId);

            // 若当前是：已录入-进行中，有预约时间，则修改后，状态变更为：已确认-进行中
            if (Objects.equals(dbOrderWork.getStatus(), OrderStatusConsts.WORK_STATUS_INPUT)
                    && Objects.equals(dbOrderWork.getResultStatus(), OrderStatusConsts.WORK_RESULT_DOING)
                    && Objects.nonNull(factoryUpdateOrderDTO.getDutyTime())) {
                factoryUpdateOrderDTO.setStatus(OrderStatusConsts.WORK_STATUS_CONFIRM);
            }

            // 确认
            if (Objects.equals(opType, OrderConsts.ORDER_OP_TYPE_CONFIRM)) {
                OperatePermissionVO operatePermission = orderWorkOperatePermissionBService.getOperatePermission(
                        orderId, workId, OrderConsts.ORDER_OP_TYPE_CONFIRM);
                if (!operatePermission.getCanOperate()) {
                    return ResultDTO.fail(operatePermission.getMsg());
                }

                factoryOrderBService.saveConfirmOrder(factoryUpdateOrderDTO);
            }
            // 修改
            else {
                OperatePermissionVO operatePermission = orderWorkOperatePermissionBService.getOperatePermission(
                        orderId, workId, OrderConsts.ORDER_OP_TYPE_UPDATE);
                if (!operatePermission.getCanOperate()) {
                    return ResultDTO.fail(operatePermission.getMsg());
                }

                // 子公司角色修改订单不触发分单撤回、派单撤回
                boolean branchCompany = super.isBranchCompany();
                factoryUpdateOrderDTO.setVerifyDistributeBack(!branchCompany);
                factoryUpdateOrderDTO.setVerifyAssignBack(!branchCompany);

                factoryOrderBService.updateOrder(factoryUpdateOrderDTO);
            }

            return ResultDTO.success();
        } catch (OmsBaseException e) {
            return ResultDTO.fail(e.getMessage());
        } catch (Exception e) {
            logger.error("{}", e.getMessage());
            logger.error(ExceptionUtil.getStackTrace(e));
            return ResultDTO.fail(e.getMessage());
        }
    }
    
    /**
     * 设置订单修改view
     *
     * @param mv
     * @param orderBO
     * @param updateDisabledFields
     */
    private void setUpdateView(ModelAndView mv, OrderBO orderBO, Set<String> updateDisabledFields) {
        OrderWork orderWork = orderBO.getOrderWork();


        if (Objects.equals(OrderConsts.ORDER_SOURCE_TYPE_FACTORY, orderWork.getSourceType())) {
            // 厂商单
            mv.setViewName("factory/work/modify/update");
        } else {
            // 非厂商单
            mv.setViewName("work/modify/update");
        }
        log.info("[{}]不能修改字段disabledFields=[{}]", orderWork.getOrderId(), JSON.toJSONString(updateDisabledFields));
        mv.addObject("disabledFields", updateDisabledFields);
        mv.addObject("orderId", orderWork.getOrderId());
        mv.addObject("workId", orderWork.getWorkId());
    }

    /**
     * 设置普通单修改数据
     *
     * @param mv
     * @param orderBO
     */
    private ZsNormalUpdateOrderVO setNormalOrderView(ModelAndView mv, OrderBO orderBO, boolean isAddOrder, boolean includeDisabledProduct) {
        ZsNormalUpdateOrderVO zsNormalUpdateOrderVO = zsOrderWorkBService.findUpdateOrderWorkVO(orderBO);

        Integer platWork = orderBO.getOrderWork().getPlatWork();
        Integer bizType = orderBO.getOrderWork().getBizType();
        Integer servCategId = orderBO.getOrderDetail().getServCategId();
        Integer showProductId = orderBO.getOrderWork().getShowProductId();
        Integer productId = orderBO.getOrderDetail().getProductId();
        Integer manageCompanyId = orderBO.getOrderWork().getManageCompanyId();
        Integer servItemType = orderBO.getOrderWork().getServItemType();
        logger.info("zsNormalUpdateOrderVO--{}", zsNormalUpdateOrderVO);

        // 手机号是座机，要重新录入真实号码
        if (MobileUtil.isExtensionPhone(zsNormalUpdateOrderVO.getTelephone())) {
            zsNormalUpdateOrderVO.setTelephone("");
            zsNormalUpdateOrderVO.setHideTelephone("");
        }

        if (Objects.nonNull(zsNormalUpdateOrderVO.getDutyTime())) {
            // 先设置原预约时间
            mv.addObject("originalDutyTime", DateUtil.dateFormatToString(zsNormalUpdateOrderVO.getDutyTime(), DateUtil.FORMAT_DEFAULT));
        }

        zsNormalUpdateOrderVO.setTodayDutyTime(true);
        // 如果订单状态属于领单前，预约时间需要重新推荐
        if (orderBO.getOrderWork().getStatus() < OrderStatusConsts.WORK_STATUS_TAKE) {
            WorkOrderScheduleQuery query = new WorkOrderScheduleQuery();
            query.setPlatWork(orderBO.getOrderWork().getPlatWork());
            query.setPlat(orderBO.getOrderWork().getPlat());
            query.setBizType(orderBO.getOrderWork().getBizType());
            query.setProductGroupId(orderBO.getOrderWork().getServProductGroupId());
            query.setCityId(orderBO.getOrderWork().getCityId());
            String defaultDutyTime = zsOrderWorkScheduleBService.getBackStageDefaultDutyTime(query);
            zsNormalUpdateOrderVO.setDutyTime(DateUtil.dateFormatToDate(defaultDutyTime, DateUtil.FORMAT_DEFAULT));
            String day = DateUtil.dateFormatToString(zsNormalUpdateOrderVO.getDutyTime(), DateUtil.FORMAT_DATE);
            String today = DateUtil.dateFormatToString(DateUtil.getNow(), DateUtil.FORMAT_DATE);
            if (!Objects.equals(day, today)) {
                zsNormalUpdateOrderVO.setTodayDutyTime(false);
            }
        }

        zsNormalUpdateOrderVO.setRequestId(IdUtil.simpleUUID());
        // 订单
        mv.addObject("orderInfo", zsNormalUpdateOrderVO);
        // 性别
        mv.addObject("gender", super.dictModel2KVDict(GlobalDict.getGenderList()));
        // 订单类型
        mv.addObject("type", super.dictModel2KVDict(OrderConsts.getOrderTypeList()));
        // 产品类型
        mv.addObject("productShowType", super.dictModel2KVDict(OrderConsts.getProductShowTypeList()));
        // 工单服务项类型
        mv.addObject("servItemType", servItemType);
        // 价格表id
        mv.addObject("tariffId", orderBO.getOrderProductList().get(0).getTariffId());
        // 外部店铺
        ExternalShopVO externalShopVO = this.getOrderExternalShop(zsNormalUpdateOrderVO);
        mv.addObject("orderExternalShop", externalShopVO);

        if (Objects.equals(OrderConsts.ORDER_SOURCE_TYPE_FACTORY, orderBO.getOrderWork().getSourceType())) {

            // 业务类型
            mv.addObject("bizTypeList", super.dictModel2KVDict(OrderConsts.getOrderBizTypeFAndCList()));
            // 厂商列表
            mv.addObject("factoryList", super.getFactoryListById(zsNormalUpdateOrderVO.getOrderFactory().getFactoryId()));
            // 服务分类
            mv.addObject("servCategList", super.getServCategByChannelIdAndShowTypeAndCityId(zsNormalUpdateOrderVO.getChannelId(), BaseProductConsts.ERP_SHOW_TYPE, zsNormalUpdateOrderVO.getCityId()));
            ProductQueryDTO queryDTO = ProductQueryDTO.builder()
                    .plat(platWork).bizType(bizType)
                    .servCategId(servCategId).showType(BaseProductConsts.ERP_SHOW_TYPE)
                    .cityId(orderBO.getOrderWork().getCityId())
                    .channelId(orderBO.getOrderWork().getChannelId())
                    .isIncludeDisabled(includeDisabledProduct).build();
            mv.addObject("productList", super.getServProductList(queryDTO));

        } else {
            // 服务分类
            mv.addObject("servCategList", super.getShowServCategList());

            // 前端产品
            List<KVDict> showProductList = super.getServProductList(ProductQueryDTO.builder()
                    .cityId(orderBO.getOrderWork().getCityId())
                    .channelId(orderBO.getOrderWork().getChannelId())
                    .bizType(bizType).servCategId(servCategId)
                    .showType(BaseProductConsts.EC_SHOW_TYPE)
                    .isIncludeDisabled(includeDisabledProduct).build());
            // 加入禁用前台产品关联的后台产品
            ProductQueryDTO queryDTO = ProductQueryDTO.builder().plat(platWork).bizType(bizType).servCategId(servCategId).showType(BaseProductConsts.EC_SHOW_TYPE).
                    isIncludeDisabled(false).cityId(orderBO.getOrderWork().getCityId()).
                    channelId(orderBO.getOrderWork().getChannelId()).build();
//            List<KVDict> listByDisableShowProduct = super.getServProductListByDisableShowProduct(queryDTO);

            List<KVDict> showServProductList = Lists.newArrayListWithCapacity(showProductList.size());
            showServProductList.addAll(showProductList);
//            showServProductList.addAll(listByDisableShowProduct);

            // 后端产品
            List<KVDict> servProductList;
            if (Objects.equals(zsNormalUpdateOrderVO.getProductShowType(), GlobalConsts.NO)) {
                servProductList = super.getServProductList(ProductQueryDTO.builder()
                        .cityId(orderBO.getOrderWork().getCityId())
                        .channelId(orderBO.getOrderWork().getChannelId())
                        .bizType(bizType).servCategId(servCategId)
                        .showType(BaseProductConsts.ERP_SHOW_TYPE)
                        .isIncludeDisabled(includeDisabledProduct).build());
            } else {
                servProductList = Lists.newArrayList();
            }

            log.debug("[{}]前端产品[{}]", showProductId, showServProductList);
            log.debug("[{}]后端产品[{}]", productId, servProductList);
            if (!isAddOrder) {
                super.appendServProductListById(bizType, showProductId, showServProductList, GlobalConsts.NO);
                super.appendServProductListById(bizType, productId, servProductList, GlobalConsts.YES);
                mv.addObject("gridCompanyId", orderBO.getOrderDetail().getGridCompanyId());
                // 是否子公司角色
                mv.addObject("branchCompany", super.isBranchCompany());
            }

            log.debug("前端产品2[{}]", showServProductList);
            log.debug("后端产品2[{}]", servProductList);
            mv.addObject("showServProductList", showServProductList);
            mv.addObject("servProductList", servProductList);

            // 特殊故障现象
            mv.addObject("specialFaultPhenId", specialFaultPhenId);

            // 处理订单报价信息
            if (!mv.getModelMap().containsKey("isRework")) {
                this.processOrderFinalPriceQuotation(mv, orderBO, zsNormalUpdateOrderVO);
            }

        }
        // 故障
        mv.addObject("subsidiaryList", super.getSubsidiaryList(!NumberUtil.isNullOrZero(productId) ? productId : showProductId));
        // 品牌
        mv.addObject("brandList", super.getBrandList());
        // 省份列表
        mv.addObject("provinceList", super.getAllProvinceList());
        // 城市列表
        mv.addObject("cityList", super.getAreaListByPid(orderBO.getOrderDetail().getProvinceId()));
        // 区县列表
        // mv.addObject("countyList", super.getAreaListByPid(orderBO.getOrderWork().getCityId()));
        // 街道列表
        mv.addObject("streetList", super.getAreaDetailListByPid(orderBO.getOrderDetail().getCountyId()));
        // 覆盖区域
        mv.addObject("countyList", super.getPointAreaSupport(manageCompanyId, orderBO.getOrderWork().getCityId()));
        // 预约失败原因
        mv.addObject("dutyFailReasonList", super.dictModel2KVDict(OrderDutyConsts.getDutyFailReasonList()));
        // 下单便捷标签
        mv.addObject("commonRemarkList", this.listInputRemark(orderBO.getOrderWork()));

        return zsNormalUpdateOrderVO;
    }

    private ExternalShopVO getOrderExternalShop(ZsNormalUpdateOrderVO zsNormalUpdateOrderVO) {
        OrderExternalShop orderExternalShop = orderExternalShopService.findByOrderIdAndWorkId(zsNormalUpdateOrderVO.getOrderId(), zsNormalUpdateOrderVO.getWorkId());
        if (Objects.isNull(orderExternalShop)) {
            return null;
        }
        ExternalShopVO vo = new ExternalShopVO();
        vo.setExternalShopId(orderExternalShop.getExternalShopId());
        vo.setInternalShopId(Objects.isNull(orderExternalShop.getInternalShopId()) ? null : orderExternalShop.getInternalShopId().intValue());
        vo.setInternalShopName(orderExternalShop.getInternalShopName());
        vo.setInternalBranchShopName(orderExternalShop.getInternalBranchShopName());
        if (StringUtil.isBlank(orderExternalShop.getInternalBranchShopName())) {
            vo.setShowShopName(String.format("%s", orderExternalShop.getInternalShopName()));
        }else {
            vo.setShowShopName(String.format("%s（%s）", orderExternalShop.getInternalShopName(), orderExternalShop.getInternalBranchShopName()));
        }

        if (NumberUtil.isNullOrZero(orderExternalShop.getInternalShopId())) {
            return vo;
        }
        try {
            ResponseDTO<MarketingShopDRO> responseDTO = marketingShopListRemoteService.getBaseById(orderExternalShop.getInternalShopId().intValue());
            if (!responseDTO.isSuccess()) {
                return vo;
            }
            if (Objects.isNull(responseDTO.getData())) {
                return vo;
            }
            MarketingShopDRO dro = responseDTO.getData();
            vo.setCooperationId(dro.getCooperationId());
            if (StringUtil.isBlank(dro.getBranchName())) {
                vo.setShowShopName(String.format("%s-%s", dro.getName(), dro.getChannelThrName()));
            }else {
                vo.setShowShopName(String.format("%s（%s）-%s", dro.getName(), dro.getBranchName(), dro.getChannelThrName()));
            }
        } catch (Exception e) {

        }

        return vo;
    }

    /**
     * 设置渠道列表
     * @param mv
     * @param zsNormalUpdateOrderVO
     */
    private void setUpdateOrderChannelList(ModelAndView mv, ZsNormalUpdateOrderVO zsNormalUpdateOrderVO, Integer bizModeSource) {
        if (zsNormalUpdateOrderVO.getOrderFactory() == null) {
            // 渠道列表
            ChannelListQuery channelListQuery = ChannelListQuery.builder().plat(zsNormalUpdateOrderVO.getPlat()).
                    excludeDisabledOrderInput(true).
                    excludeDisabled(true).
                    isPermit(true).
                    factoryChannel(false).
                    bizModeSource(bizModeSource).build();
            List<KVDict> channelList = super.getChannelList(channelListQuery);

            // 线上渠道，并且被禁用需要显示
            int orderChannelId = zsNormalUpdateOrderVO.getChannelId();
            if (!channelList.stream().anyMatch(item -> Integer.parseInt(item.getValue().toString()) == orderChannelId)) {
                ResponseDTO<ChannelDRO> responseDTO = channelListRemoteService.getByChannelId(zsNormalUpdateOrderVO.getChannelId());
                ChannelDRO channelDRO = responseDTO.getData();
                if (channelDRO != null) {
                    KVDict<Integer> kvDict = new KVDict<>();
                    kvDict.setValue(channelDRO.getChannelId());
                    kvDict.setText(channelDRO.getName());
                    channelList.add(kvDict);
                }
            }
            mv.addObject("channelList", channelList);
        }

    }

	private void processCopyOrder(ModelAndView mv, OrderWork orderWork, ZsNormalUpdateOrderVO zsNormalUpdateOrderVO){
        // 退款单->新单
        if (Objects.equals(zsNormalUpdateOrderVO.getType(), OrderConsts.ORDER_TYPE_REFUND)) {
            zsNormalUpdateOrderVO.setType(OrderConsts.ORDER_TYPE_NEW);
        }

        // 产品被禁用则，不自动带入信息，同时也不自动带入：故障
        ProductBaseQuery productDIO = new ProductBaseQuery();
        productDIO.setProductId(Objects.equals(zsNormalUpdateOrderVO.getProductShowType(), GlobalConsts.YES) ? zsNormalUpdateOrderVO.getShowProductId() : zsNormalUpdateOrderVO.getProductId());
        ResponseDTO<List<ProductBaseDRO>>  productResponseDTO = productForeignListRemoteService.listBaseDROByQuery(productDIO);
        logger.debug("查询产品信息入参：【{}】，出参：【{}】", productDIO, JSON.toJSONString(productResponseDTO));
        if (productResponseDTO.isSuccess() && CollectionUtil.isNotNullOrEmpty(productResponseDTO.getData())) {
            if (Objects.nonNull(productResponseDTO.getData()) && Objects.equals(productResponseDTO.getData().get(0).getStatus(), GlobalConsts.NO)) {
                if (Objects.equals(zsNormalUpdateOrderVO.getProductShowType(), GlobalConsts.YES)) {
                    zsNormalUpdateOrderVO.setShowProductId(null);
                } else {
                    zsNormalUpdateOrderVO.setProductId(null);
                }
                // 不带入故障信息
                zsNormalUpdateOrderVO.getOrderProductList().get(0).setFaultIdList(null);
                // 清空故障列表
                mv.addObject("subsidiaryList", Lists.newArrayList());
            }
        }

        // 若：产品分类或服务分类被禁用则，不自动带入信息，同时也不自动带入：产品和故障
        ResponseDTO<CategServDRO> servCategResponseDTO = categServListRemoteService.getByServCategId(orderWork.getServCategId());
        if (productResponseDTO.isSuccess()) {
            if (Objects.nonNull(servCategResponseDTO.getData()) && Objects.equals(servCategResponseDTO.getData().getStatus(), GlobalConsts.NO)) {
                // 不带入服务分类信息
                zsNormalUpdateOrderVO.setServCategId(null);
                zsNormalUpdateOrderVO.setServCategName(null);
//                // 不带入产品和故障信息
//                zsNormalUpdateOrderVO.setOrderProductList(Lists.newArrayList());
                zsNormalUpdateOrderVO.setProductId(null);
                mv.addObject("productList", Lists.newArrayList());
                // 清空故障列表
                mv.addObject("subsidiaryList", Lists.newArrayList());
            }
        }

        // 厂商单
        if (Objects.equals(OrderConsts.ORDER_SOURCE_TYPE_FACTORY, orderWork.getSourceType())) {
            mv.setViewName("factory/work/modify/copy");
        }
        // 非厂商单
        else {
            // 若原订单渠道不允许录单，则复制后不自动带入原渠道，若下单平台与服务平台不一致，则渠道信息不自动带入，且新页面仅加载对应服务平台渠道；
//            ResponseDTO<ChannelDRO> responseDTO = channelListRemoteService.getByChannelId(orderWork.getChannelId());
//            ChannelDRO channelDRO = responseDTO.getData();
            if (!Objects.equals(orderWork.getPlat(), orderWork.getPlatWork())) {
                zsNormalUpdateOrderVO.setChannelId(null);
            }
            // 渠道列表
            List<KVDict> channelList = super.getChannelListByDept(orderWork.getPlatWork());
            mv.addObject("channelList", channelList);

            // 工程师加单，复制时渠道设置为工程师推荐
            try {
                if (zsNormalUpdateOrderVO.getChannelId() != null) {
                    Integer channelId = baseCodeService.getChannelId(GlobalConsts.PLAT_MARK_ZMN,
                            TagConsts.TAG_TWO_TYPE_OMS_CHANNEL_MASTER);
                    if (Objects.equals(zsNormalUpdateOrderVO.getChannelId(), channelId)) {
                        zsNormalUpdateOrderVO.setChannelId(baseCodeService.getChannelId(GlobalConsts.PLAT_MARK_ZMN,
                                TagConsts.TAG_TWO_TYPE_OMS_CHANNEL_MASTER_RECOMMEND));
                    }
                }
            } catch (OmsBaseException e) {
                logger.error(ExceptionUtil.getStackTrace(e));
            }
        }
    }

    private List<KVDict<Integer>> listInputRemark(OrderWork orderWork) {
        List<KVDict<Integer>> remarkList = baseCodeService.listInputRemark();

        OrderRemark orderRemark = orderRemarkService.findByOrderIdAndType(orderWork.getOrderId(), orderWork.getWorkId(), OrderConsts.ORDER_REMARK_TYPE_INPUT);
        if (Objects.isNull(orderRemark)) {
            return remarkList;
        }

        List<OrderRemarkDetail> remarkDetails = orderRemarkDetailService.listOrderRemarkDetailByRemarkId(orderWork.getOrderId(), orderWork.getWorkId(), orderRemark.getRemarkId());
        if (CollectionUtil.isNullOrEmpty(remarkDetails)) {
            return remarkList;
        }

        List<Integer> checkRemarkIdList = remarkDetails.stream().map(OrderRemarkDetail::getMapId).collect(Collectors.toList());

        remarkList.forEach(remark -> {
            if (checkRemarkIdList.contains(remark.getValue())) {
                remark.setSelected(true);
            }
        });
        return remarkList;
    }

    private List<String> listReworkReason() {
        List<TagsDRO> tagList = baseCodeService.listBaseCodeMap(com.zmn.consts.GlobalConsts.PLAT_MARK_ZMN, OrderConsts.BASE_CODE_MAP_ONE_TYPE_REWORK_REASON, null, null);

        if (CollectionUtil.isNullOrEmpty(tagList)) {
            return Lists.newArrayList();
        }

        return tagList.stream().map(TagsDRO::getName).collect(Collectors.toList());
    }

    /**
     *  验证电话或者产品是否修改过
     * @param zsNormalUpdateOrderDTO
     * @return
     */
    private boolean verifyTelephoneOrProduct(ZsNormalUpdateOrderDTO zsNormalUpdateOrderDTO) {
        try {
            List<OrderProductDTO> orderProductList = zsNormalUpdateOrderDTO.getOrderProductList();
            if (CollectionUtil.isNullOrEmpty(orderProductList)) {
                return Boolean.FALSE;
            }
            VerifyTelephoneOrProductDTO dto = new VerifyTelephoneOrProductDTO();
            BeanMapper.copy(zsNormalUpdateOrderDTO, dto);
            Integer productId = orderProductList.get(0).getProductId();
            Integer showProductId = orderProductList.get(0).getShowProductId();
            Integer productShowType = orderProductList.get(0).getProductShowType();
            dto.setProductShowType(productShowType);
            if (Objects.equals(1, productShowType)) {
                dto.setProductId(productId);
            } else {
                dto.setProductId(showProductId);
            }
            return duplicateOrderBService.verifyTelephoneOrProduct(dto);
        } catch (Exception ex) {
            logger.error("#verifyTelephoneOrProduct验证电话或者产品是否修改过 error= {}", ex);
        }
        return Boolean.FALSE;
    }

    private void processOrderFinalPriceQuotation(ModelAndView mv, OrderBO orderBO, ZsNormalUpdateOrderVO zsNormalUpdateOrderVO) {
        mv.addObject("isHaveQuote", false);
        // 标记多服务项
        mv.addObject("multiServiceItem", false);

        OrderWork orderWork = orderBO.getOrderWork();

        // 判断试点
        AdvanceQuoteOpenQuery advanceQuoteOpenQuery = AdvanceQuoteOpenQuery.builder()
                .cityId(zsNormalUpdateOrderVO.getCityId())
                .servCategId(zsNormalUpdateOrderVO.getServCategId())
                .showProductType(NumberUtil.isNotNullOrZero(zsNormalUpdateOrderVO.getProductId()) ? BaseProductConsts.ERP_SHOW_TYPE : BaseProductConsts.EC_SHOW_TYPE)
                .productId(NumberUtil.isNotNullOrZero(zsNormalUpdateOrderVO.getProductId()) ? zsNormalUpdateOrderVO.getProductId() : zsNormalUpdateOrderVO.getShowProductId())
                .build();
        boolean openAdvanceQuote = baseCodeService.isOpenAdvanceQuote(advanceQuoteOpenQuery);
        if (!openAdvanceQuote) {
            return;
        }

        OrderProduct orderProduct = orderBO.getOrderProductList().get(0);

        // 查询下单报价相关信息
        OrderFinalPriceQuotationQuery quotationQuery = new OrderFinalPriceQuotationQuery();
        quotationQuery.setOrderId(orderBO.getOrderWork().getOrderId());
        quotationQuery.setWorkId(orderBO.getOrderWork().getWorkId());
        List<OrderFinalPriceQuotation> quotationList = orderFinalPriceQuotationService.listByQuery(quotationQuery);

        OrderFinalPriceQuotation quotation = new OrderFinalPriceQuotation();
        if (CollectionUtil.isNotNullOrEmpty(quotationList)) {
            quotation = quotationList.get(0);
        }
        Integer quoteType = Optional.ofNullable(quotation.getQuotationType()).orElse(OrderAdvanceConsts.QUOTE_TYPE_SERVICE_ITEM_TYPE);

        // 服务项目报价
        List<OrderServiceItem> serviceItemList = orderServiceItemService.listByOrderId(orderWork.getOrderId());
        serviceItemList = serviceItemList.stream()
                .filter(item -> !Objects.equals(item.getServItemGroupId(), ServiceItemTypeEnum.ADDITION_ITEM.getType()))
                .collect(Collectors.toList());

        // 基础查询类
        AdvanceQuoteBaseQuery baseQuery = AdvanceQuoteBaseQuery.builder()
                .bizType(orderWork.getBizType())
                .channelId(orderWork.getChannelId())
                .cityId(orderWork.getCityId())
                .showProductId(orderWork.getShowProductId())
                .tariffId(orderProduct.getTariffId())
                .brandId(orderProduct.getBrandId())
                .categId(orderProduct.getCategId())
                .platWork(orderWork.getPlatWork())
                .build();

        boolean isHaveQuote = false;
        if (Objects.equals(quoteType, OrderAdvanceConsts.QUOTE_TYPE_FAULT_PHEN)
            && CollectionUtil.isNullOrEmpty(serviceItemList)) {
            // 故障现象报价
            AdvanceQuotePhenQuery phenQuery = BeanMapper.map(baseQuery, AdvanceQuotePhenQuery.class);
            phenQuery.setPhenId(quotation.getPhenId());
            // 故障现象
            List<KVDict> faultPhenList = advanceQuoteListBService.
                    listFaultPhen(baseQuery);
            // 二级分类
            List<CategVO> categList = advanceQuoteListBService.
                    listProductCateg(phenQuery);
            // 产品
            List<ProductVO> quoteProductList = advanceQuoteListBService.listProduct(phenQuery);

            // 三项数据全有，回显，否则重新报价
            if (CollectionUtil.isNullOrEmpty(categList)
                    || CollectionUtil.isNullOrEmpty(quoteProductList)) {
                return;
            }

            zsNormalUpdateOrderVO.setQuoteType(OrderAdvanceConsts.QUOTE_TYPE_FAULT_PHEN);

            zsNormalUpdateOrderVO.setPhenId(quotation.getPhenId());

            mv.addObject("categList", categList);
            zsNormalUpdateOrderVO.setProductCateg(quotation.getCategId());

            mv.addObject("quoteProductList", quoteProductList);
            zsNormalUpdateOrderVO.setQuotationProductId(quotation.getProductId());
            isHaveQuote = true;

        } else if (serviceItemList.size() <= 1){
            Integer itemId = quotation.getServItemId();
            // 过滤附加项
            Optional<OrderServiceItem> serviceItemOptional = serviceItemList.stream()
                    .filter(e -> !Objects.equals(e.getServItemGroupId(), ServiceItemTypeEnum.ADDITION_ITEM.getType()))
                    .findFirst();
            if (serviceItemOptional.isPresent()) {
                itemId = serviceItemOptional.get().getServItemId();
            }

            if (NumberUtil.isNullOrZero(itemId)) {
                return;
            }

            AdvanceQuoteItemQuery itemQuery = BeanMapper.map(baseQuery, AdvanceQuoteItemQuery.class);
            itemQuery.setItemId(itemId);

            // 服务项目
            List<KVDict> itemList = advanceQuoteListBService.
                    listServiceItem(baseQuery);
            // 二级分类
            List<CategVO> categList = advanceQuoteListBService.listProductCategWithItemId(itemQuery);
            // 产品
            List<ProductVO> quoteProductList = advanceQuoteListBService.listProductWithItem(itemQuery);
            // 三项数据全有，回显，否则重新报价
            if (CollectionUtil.isNullOrEmpty(itemList)
                    || CollectionUtil.isNullOrEmpty(categList)
                    || CollectionUtil.isNullOrEmpty(quoteProductList)) {
                return;
            }

            zsNormalUpdateOrderVO.setQuoteType(OrderAdvanceConsts.QUOTE_TYPE_SERVICE_ITEM_TYPE);

            mv.addObject("itemList", itemList);
            zsNormalUpdateOrderVO.setItemId(itemId);

            mv.addObject("categList", categList);
            zsNormalUpdateOrderVO.setProductCateg(quotation.getCategId());

            mv.addObject("quoteProductList", quoteProductList);
            zsNormalUpdateOrderVO.setQuotationProductId(quotation.getProductId());
            isHaveQuote = true;
        } else if (serviceItemList.size() > 1){
            isHaveQuote = true;

            zsNormalUpdateOrderVO.setQuoteType(OrderAdvanceConsts.QUOTE_TYPE_SERVICE_ITEM_TYPE);
            // 标记多服务项
            mv.addObject("multiServiceItem", true);
        }

        if (isHaveQuote) {
            // 故障现象 - 用于前端回显
            List<KVDict> faultPhenList = advanceQuoteListBService.
                    listFaultPhen(baseQuery);
            mv.addObject("faultPhenList", faultPhenList);

            // 禁用后台产品选择按钮
            mv.addObject("isHaveQuote", isHaveQuote);

            // 显示前台产品
            zsNormalUpdateOrderVO.setProductShowType(BaseProductConsts.EC_SHOW_TYPE);
            zsNormalUpdateOrderVO.setProductShowType(BaseProductConsts.EC_SHOW_TYPE);
        }

    }
}
